/*
 * 文件名称: AbstractPathFilter.java Copyright 2011-2016 Ximalaya All right reserved.
 */
package top.zxybird.common.web.filter;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;

/**
 * Set response header cache attributes
 * <p>
 * if need it, please config this class in the web.xml
 *
 * @author cossea
 *
 */
public class NoCacheFilterBean implements Filter {

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
  }

  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    httpResponse.addHeader("Cache-Control", "no-cache");
    httpResponse.addHeader("Cache-Control", "no-store");
    httpResponse.addHeader("Pragma", "no-cache");
    long time = System.currentTimeMillis();
    httpResponse.addDateHeader("Date", time);
    // httpResponse.addDateHeader("Last-Modified", time);
    httpResponse.addDateHeader("Expires", 0);
    chain.doFilter(request, response);
  }

  @Override
  public void destroy() {
  }

}
